package com.hb.znpt.model;

import com.hb.znpt.BuildConfig;
import com.hb.znpt.utils.AESHttpUtil;
import com.hb.znpt.utils.Constants;
import com.hb.znpt.utils.LogUtils;
import com.unitlib.base.base.BaseModel;
import com.unitlib.base.utils.SPUtils;

import java.util.Calendar;
import java.util.Date;

import io.reactivex.Observable;
import rxhttp.wrapper.param.RxHttp;

public class LandAddModel extends BaseModel {

    Calendar calendar = Calendar.getInstance();

    public Observable<String> send(String zwmc, String zwmj, String deptid) {
        int cunYear = calendar.get(Calendar.YEAR);
        long t = new Date().getTime();
        String json = "{\"year\":\"" + cunYear +
                "\",\"sfz\":\"" + SPUtils.getInstance().getString(Constants.SP_USERCARD) +
                "\",\"token\":\"" + SPUtils.getInstance().getString(Constants.SP_TOKEN) +
                "\",\"bb\":\"" + BuildConfig.VERSION_CODE +
                "\",\"deptid\":\"" + deptid +
                "\",\"zwmc\":\"" + zwmc +
                "\",\"zwmj\":\"" + zwmj +
                "\",\"zwxm\":\"" + SPUtils.getInstance().getString(Constants.SP_NAME) +
                "\",\"zwsfz\":\"" + SPUtils.getInstance().getString(Constants.SP_USERCARD) +
                "\",\"timestamp\":" + t + "}";
        LogUtils.e(TAG, json);
        String encrypt = null;
        try {
            encrypt = AESHttpUtil.加密(json);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return RxHttp.postJson(Constants.URL_ZWSAVE)
                .add("encrypt", encrypt)
                .add("timestamp", t)
                .asResponse(String.class);
    }

}
